package com.example.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.po.AccountPO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

/*
@description:
@ClassName AccountMapper
@author chen
@create 2025-08-26 10:58
@Version 1.0
*/
public interface AccountMapper extends BaseMapper<AccountPO>
{
    /**
     * 增加账户余额
     *
     * @param accountId
     * @param price
     * @return
     */
    @Update("update t_account_lesson036 set balance = balance + #{price} where id = #{accountId} and #{price}>0")
    int balanceAdd(@Param("accountId") String accountId, @Param("price") BigDecimal price);

    /**
     * 减少账户余额
     *
     * @param accountId
     * @param price
     * @return
     */
    @Update("update t_account_lesson036 set balance = balance - #{price} where id = #{accountId} and balance - #{price} >=0 and #{price}>0")
    int balanceSubtract(@Param("accountId") String accountId, @Param("price") BigDecimal price);
}
